package com.digital.smartgrow.controller.businesscenter;

import com.digital.smartgrow.common.util.WebTool;
import com.digital.smartgrow.dto.businesscenter.DynamicFormDataPageDTO;
import com.digital.smartgrow.entity.businesscenter.DynamicFormData;
import com.digital.smartgrow.entity.datacenter.Teacher;
import com.digital.smartgrow.service.businesscenter.DynamicFormDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 动态表单数据 前端控制器
 * </p>
 *
 * @author xiewb
 * @since 2022-04-23
 */
@Api(tags = "动态表单数据")
@RestController
@RequestMapping("${context.prefix}/dynamicFormData")
public class DynamicFormDataController {

    @Autowired
    private DynamicFormDataService dynamicFormDataService;

    @ApiOperation(value = "列表分页查询")
    @PostMapping("/getListByPage")
    public Object getListByPage(@RequestBody DynamicFormDataPageDTO dynamicFormDataPageDTO){
        return dynamicFormDataService.getListByPage(dynamicFormDataPageDTO);
    }

    @ApiOperation(value = "动态表单数据-详情")
    @GetMapping("/getInfo")
    public Object getInfo(Integer id){
        if (id == null) return "id不能为空";
        return dynamicFormDataService.getInfo(id);
    }

    @ApiOperation(value = "动态表单数据-新增")
    @PostMapping("/add")
    public Object add(@Valid @RequestBody DynamicFormData dynamicFormData){
        Teacher teacher = WebTool.getCurrentUser();
        dynamicFormData.setCreateId(teacher.getId());
        return dynamicFormDataService.save(dynamicFormData);
    }

    @ApiOperation(value = "动态表单数据-统计")
    @GetMapping("/getFormCount")
    public Object getFormCount(Integer formTemplateId){
        if (formTemplateId == null) return "模板id不能为空";
        return dynamicFormDataService.getFormCount(formTemplateId);
    }
}
